package com.catchu.pattern.creational.迭代器模式.d双向迭代器.aggregate;

import com.catchu.pattern.creational.迭代器模式.b进阶.model.PayModel;
import com.catchu.pattern.creational.迭代器模式.d双向迭代器.iterator.Iterator;
import com.catchu.pattern.creational.迭代器模式.d双向迭代器.iterator.ListPayIterator;

import java.util.ArrayList;
import java.util.List;

/**
 * 用集合实现的聚合类
 */
public class ListPayAggregate extends BasicAggregate {

    private List<PayModel> list = new ArrayList<>();

    @Override
    public Iterator createIterator() {
        return new ListPayIterator(this);
    }

    public void calcPay(){
        PayModel pm1 = new PayModel();
        pm1.setName("张三");
        pm1.setSalary(2000.0);

        PayModel pm2 = new PayModel();
        pm2.setName("李四");
        pm2.setSalary(4500.2);

        list.add(pm1);
        list.add(pm2);
    }

    public List getList(){
        return list;
    }

    public Integer size(){
        return list.size();
    }

    public Object get(int index){
        Object result = null;
        if(index<list.size()){
            result = list.get(index);
        }
        return result;
    }
}
